#ifndef SESSIONFRIENDAREA_H
#define SESSIONFRIENDAREA_H

#include <QWidget>
#include <QScrollArea>
#include <QGridLayout>
#include <QLabel>

//会话的类型
enum SessionType{
    SESSION_TYPE,
    FRIEND_TYPE,
    APPLY_TYPE
};

class SessionFriendAreaItem;

class SessionFriendArea : public QScrollArea
{
    Q_OBJECT
public:
    explicit SessionFriendArea(QWidget *parent = nullptr);
    void addItem(SessionType type, QWidget* owner, const QString& id, const QIcon& avatar, const QString& name , const QString& text);
private:
    QWidget* container;
public:
    SessionFriendAreaItem* lastSelectedItem;
signals:
};



class SessionFriendAreaItem : public QWidget
{
    Q_OBJECT
public:
    SessionFriendAreaItem(QWidget* owner, const QIcon& icon, const QString& name, const QString& text);
    void select(); //选中当前元素
    void clear();

    //重写鼠标进入离开事件
    void enterEvent(QEnterEvent* event) override;
    void leaveEvent(QEvent* event) override;
    void paintEvent(QPaintEvent* event) override;
    void mousePressEvent(QMouseEvent *event) override;


    //用于后续的操作
    virtual void active();

private:
    bool selected;
    QWidget* owner;         // 该 Item 所属的 QWidget. 此处填写 SessionFriendArea

protected:
    QLabel* lastMessage;
    QGridLayout* layout;
};



class SessionItem : public SessionFriendAreaItem
{
    Q_OBJECT
public:
    SessionItem(QWidget* owner, const QString& sessionId,const QIcon& avatar, const QString& name, const QString& lastMessage);
    void active();
private:
    QString sessionId;
};


class FriendItem : public SessionFriendAreaItem
{
    Q_OBJECT
public:
    FriendItem(QWidget* owner, const QString& id, const QIcon& avatar, const QString& name, const QString& descripition);
    void active();
private:
    QString userId;
};


class ApplyItem : public SessionFriendAreaItem
{
    Q_OBJECT
public:
    ApplyItem(QWidget* owner,const QString& id, const QIcon& avatar, const QString& name);
    void active();
private:
    QString userId;
};

#endif // SESSIONFRIENDAREA_H
